/*
 * Copyright (C) 2008 Wim Crols <twimpiex@gnx.be>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License Version 3
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

package be.gnx.event.consumer.receiver.model;

import java.util.HashMap;

public enum EventLevel {

  ALL("ALL", 0),
  TRACE("TRACE", 1),
  DEBUG("DEBUG", 2),
  INFO("INFO", 3),
  WARN("WARN", 4),
  ERROR("ERROR", 5),
  FATAL("FATAL", 6),
  OFF("OFF", 7);

  private static final long serialVersionUID = 39580928759874l;

  private final String description;

  private final int intLevel;

  private static HashMap<String, EventLevel> eventLevelDescriptionHashMap = new HashMap<String, EventLevel>();

  private static HashMap<Integer, EventLevel> eventLevelIntegerHashMap = new HashMap<Integer, EventLevel>();

  static {
    for (EventLevel eventLevel : EventLevel.values()) {
      eventLevelDescriptionHashMap.put(eventLevel.description, eventLevel);
      eventLevelIntegerHashMap.put(eventLevel.intLevel, eventLevel);
    }
  }

  EventLevel(String description, int intLevel) {
    this.description = description;
    this.intLevel = (Integer.MAX_VALUE / 7) * intLevel;
  }

  public String getDescription() {
    return description;
  }

  public int getIntLevel() {
    return intLevel;
  }

  public static EventLevel typeOf(String description) {
    return eventLevelDescriptionHashMap.get(description);
  }

  public static EventLevel typeOf(int intLevel) {
    return eventLevelDescriptionHashMap.get(intLevel);
  }

}
